package com.kingyea.gradle.jsch;

import java.util.Properties;

import com.kingyea.gradle.extension.RemoteLinuxDeploy;

public class SessionConfiguration {
	public static int DEFAULT_PORT = 22;
	private String host;
	private int port = DEFAULT_PORT;
	private String username;
	private String password;
	
	private int timeout = 60 * 1000;//60秒
	private Properties config;
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public int getTimeout() {
		return timeout;
	}
	public void setTimeout(int timeout) {
		this.timeout = timeout;
	}
	public Properties getConfig() {
		if(config==null) {
			config = new Properties();
		}
		return config;
	}
	public void setConfig(Properties config) {
		this.config = config;
	}
	public void setConfigEntry(String key, String value) {
		this.getConfig().setProperty(key, value);
	}
	
	public static SessionConfiguration parse(RemoteLinuxDeploy linuxDeploy) {
		SessionConfiguration configuration = new SessionConfiguration();
		configuration.setUsername(linuxDeploy.getUserName());
		configuration.setPassword(linuxDeploy.getPassword());
		if(linuxDeploy.getPort()!=null) {
			configuration.setPort(linuxDeploy.getPort());
		}
		configuration.setHost(linuxDeploy.getHost());
		configuration.setConfigEntry("StrictHostKeyChecking", "no");
		return configuration;
	}
}
